package pers.kw.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 优先级队列
 */
@Configuration
public class FirstQueueConfig {

    /**
     * 交换机名称
     */
    public static final String EXCHANGE_NAME = "first.exchange";

    /**
     * 队列的名称
     */
    public static final String QUEUE_NAME = "first.queue";

    /**
     * routing_key
     */
    public static final String ROUTING_KEY = "first";

    /**
     * 配置交换机
     */
    @Bean
    public DirectExchange firstExchange() {
        return new DirectExchange(EXCHANGE_NAME, true, false, null);
    }

    /**
     * 配置队列
     */
    @Bean
    public Queue firstQueue() {
        return QueueBuilder.durable(QUEUE_NAME)
                //设置优先级
                .maxPriority(10)
                .build();
    }

    /**
     * 配置绑定关系
     */
    @Bean
    public Binding confirmBinding(@Qualifier("firstExchange") DirectExchange firstExchange,
                                  @Qualifier("firstQueue") Queue firstQueue) {
        return BindingBuilder.bind(firstQueue).to(firstExchange).with(ROUTING_KEY);
    }
}
